
function varargout = GUI_BC(varargin)
% GUI_BC MATLAB code for GUI_BC.fig
%      GUI_BC, by itself, creates a new GUI_BC or raises the existing
%      singleton*.
%
%      H = GUI_BC returns the handle to a new GUI_BC or the handle to
%      the existing singleton*.
%
%      GUI_BC('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_BC.M with the given input arguments.
%
%      GUI_BC('Property','Value',...) creates a new GUI_BC or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GUI_BC_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GUI_BC_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GUI_BC

% Last Modified by GUIDE v2.5 12-May-2013 11:40:36

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_BC_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_BC_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before GUI_BC is made visible.
function GUI_BC_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to GUI_BC (see VARARGIN)

% Choose default command line output for GUI_BC
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GUI_BC wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = GUI_BC_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on selection change in nahravky.
function nahravky_Callback(hObject, eventdata, handles)
% hObject    handle to nahravky (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns nahravky contents as cell array
%        contents{get(hObject,'Value')} returns selected item from nahravky


% --- Executes during object creation, after setting all properties.
function nahravky_CreateFcn(hObject, eventdata, handles)
% hObject    handle to nahravky (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

set(hObject, 'String', {'Reč s tichom na pozadí', 'Reč s bielym šumom na pozadí', 'Reč s hudbou na pozadí', 'Reč so zvukmi z ulice na pozadí', 'Iné *.wav'});



% --- Executes on selection change in parametrizacie.
function parametrizacie_Callback(hObject, eventdata, handles)
% hObject    handle to parametrizacie (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns parametrizacie contents as cell array
%        contents{get(hObject,'Value')} returns selected item from parametrizacie


% --- Executes during object creation, after setting all properties.
function parametrizacie_CreateFcn(hObject, eventdata, handles)
% hObject    handle to parametrizacie (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

set(hObject, 'String', {'LPCC', 'PLP', 'RASTA-PLP', 'MFCC', 'BFCC', 'RPLP','GFCC', 'GPLP', 'MVDR-MFCC', 'GTCC', 'PNCC', 'FEPSTRUM',});


% --- Executes on selection change in koeficienty.
function koeficienty_Callback(hObject, eventdata, handles)
% hObject    handle to koeficienty (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns koeficienty contents as cell array
%        contents{get(hObject,'Value')} returns selected item from koeficienty


% --- Executes during object creation, after setting all properties.
function koeficienty_CreateFcn(hObject, eventdata, handles)
% hObject    handle to koeficienty (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
    
end

set(hObject, 'String', {'Základné', 'Diferenčné', 'Akceleračné', 'Všetkych 39'});


% --- Executes on selection change in vyber_spek_koef.
function vyber_spek_koef_Callback(hObject, eventdata, handles)
% hObject    handle to vyber_spek_koef (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns vyber_spek_koef contents as cell array
%        contents{get(hObject,'Value')} returns selected item from vyber_spek_koef


% --- Executes during object creation, after setting all properties.
function vyber_spek_koef_CreateFcn(hObject, eventdata, handles)
% hObject    handle to vyber_spek_koef (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

set(hObject, 'String', {'Spektrum', 'Výsledné koeficienty' , 'Waveform'});

% --- Executes on button press in load_tlac.
function load_tlac_Callback(hObject, eventdata, handles)
% hObject    handle to load_tlac (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.wav','select a wave file to load');
save load.mat


% --- Executes on button press in update.
function update_Callback(hObject, eventdata, handles)
% hObject    handle to update (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
nahravka_vyber = get(handles.nahravky, 'Value');
switch nahravka_vyber
    case 1
        [d,sr] = wavread('sb01_Clean.sph.wav');
        xxx = 'sb01_Clean.sph.wav';
    case 2
        [d,sr] = wavread('sb01_White_05dB.sph.wav');
        xxx = 'sb01_White_05dB.sph.wav';
    case 3
        [d,sr] = wavread('sb01_Music_05dB.sph.wav');
        xxx ='sb01_Music_05dB.sph.wav';
    case 4
        [d,sr] = wavread('sb01_Street_05dB.sph.wav');
        xxx = 'sb01_Street_05dB.sph.wav';    
    case 5
        load load.mat
        [d,sr] = wavread([pathname filename]);
        xxx = filename;
end

parametrizacia_vyber = get(handles.parametrizacie, 'Value');
switch parametrizacia_vyber
    case 1
        [c, spectra, vx, ax, all] = LPCC(d,sr,12); 
        a=0;
    case 2
        [c, spectra, vx, ax, all] = rastaplp(d,sr,12);
        a=0;
    case 3
        [c, spectra, vx, ax, all] = rastaplp(d,sr, 0,12); 
        a=0;
    case 4
        [ all, c, ax, vx ] = MFCC(d, sr);
        a=1;
    case 5
        [ all, c, ax, vx ] = BFCC(d, sr);
        a=1;
    case 6
        [c, spectra, vx, ax, all] = RPLP(d,sr,12);
        a=0;        
    case 7
        [ all, c, ax, vx ] = GFCC(d, sr); 
        a=1;
    case 8
        [c, spectra, vx, ax, all] = GPLP(d,sr,12);
        a=0;
    case 9
        [ all, c, ax, vx ] = MVDR_MFCC(d,sr);
         a=1;
    case 10
        [  all,  c, ax, vx  ]  = GTCCxx( d, sr , 0 );
        a=1;
    case 11
        [c , vx, ax, all] = PNCC_IEEETranForDemo_PNCC(  d, sr , 1, 0);
        a=1;
    case 12
        [c , vx , ax , all] = fepstrum_30ms_w_10ms_over(d, sr); 
        a=1;        
end

koeficienty_vyber = get(handles.koeficienty, 'Value');
switch koeficienty_vyber
    case 1
        koef = c;
    case 2
        koef = vx;
    case 3
        koef = ax;
    case 4
        koef = all;
end

spek_kep_vyber = get(handles.vyber_spek_koef, 'Value');
switch spek_kep_vyber
    case 1
        if (a == 1)
         c_idct       = idct(koef, 24);

        str_hod = mean(c_idct(:));
        smer_odch  = std(c_idct(:));

        dfar_skala_1 = 35 - str_hod;
        far_skala_2 = 10 / smer_odch;

        image(far_skala_2 * c_idct + dfar_skala_1);
        axis xy, colorbar
        xlabel('Rámce')
        ylabel('Kanály')
        title('Spektrum z výsledných koeficientov')
        else 
            cepstra = cep2spec(koef);
            imagesc(10*log10(cepstra));
            axis xy, colorbar
            xlabel('Rámce')
            ylabel('Kanály')
            title('Spektrum z výsledných koeficientov')
        end
    case 2
        imagesc(koef)
        axis xy, colorbar
            xlabel('Rámce')
        ylabel('Kep. koef.')
         title('Výsledné koeficienty')
    case 3    
 signal = wavread(xxx);
 signal = 0.99*signal/max(abs(signal));
                    samp_len = length(signal)/16000;
            delta_t = 1/16000;
            t = 0:delta_t:(samp_len-delta_t);

            % display the signal
            plot(t,signal), xlabel('Čas'), ylabel('Amplitúda'), title('Waveform')
            axis([0 t(length(signal)-1) -1 1 ]);
end
